package com.untour.seqid.config.leaf.segment.repository.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.untour.im.exception.BusinessException;
import com.untour.seqid.config.exception.SeqIdExceptionCode;
import com.untour.seqid.config.leaf.segment.dao.LeafAllocMapper;
import com.untour.seqid.config.leaf.segment.domain.LeafAllocDO;
import com.untour.seqid.config.leaf.segment.repository.LeafAllocRepository;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Set;

@Repository
public class LeafAllocRepositoryImpl extends ServiceImpl<LeafAllocMapper, LeafAllocDO>
        implements LeafAllocRepository {


    @Override
    public Set<String> queryAllBizTags() {
        return super.baseMapper.queryAllBizTags();
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMaxId(String bizTag){
        int result = super.baseMapper.updateMaxId(bizTag);
        if(result != 1){
            throw new BusinessException(SeqIdExceptionCode.LOAD_ID_ERROR);
        }
    }

    @Override
    public LeafAllocDO getLeafAlloc(String bizTag){
        return super.baseMapper.getLeafAlloc(bizTag);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateMaxIdByCustomStep(String bizTag,int step){
        super.baseMapper.updateMaxIdByCustomStep(bizTag,step);
    }
}
